//
//  CollectionDataSource.m
//  freeLance
//
//  Created by Igor Karpenko on 3/30/13.
//  Copyright (c) 2013 Mozi Development. All rights reserved.
//

#import "CollectionHeaderView.h"
#import "CollectionViewCell.h"
#import "CDCollections.h"

#import "CollectionDataSource.h"

@implementation CollectionDataSource

-(id) initWithCollection:(CDCollections *)aCollection {
	self = [super init];
	if (!self) {
		return nil;
	}
	_collection = aCollection;
	_items = [_collection.products allObjects];
	
	return self;
}


-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
	return _items.count;
}


-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView
				  cellForItemAtIndexPath:(NSIndexPath *)indexPath {
	CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellIdentifier forIndexPath:indexPath];
	cell.product = _items[indexPath.row];

	return cell;
}


-(UICollectionReusableView *) collectionView: (UICollectionView *)collectionView
		   viewForSupplementaryElementOfKind:(NSString *)kind
								 atIndexPath:(NSIndexPath *)indexPath {
    CollectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
																		  withReuseIdentifier:collectionHeaderIdentifier forIndexPath:indexPath];
	
    return headerView;
}

@end
